import { http } from "../plugins/axios"
import utils from "@/utils";
import {CacheEnum} from "@/enum/userEnum"
export interface User{
    id:number
    name:string;
     avatar:string,
     user_type:number,
     create_time:string
}
export interface ILoginData {
  userName: string
  password: string
}
 function userInfo(){
      return http.request<User>({
        url:`info`,
        method: "get",
        headers: {token:utils.store.get(CacheEnum.TOKEN_NAME)},  
       
        
      })
}

interface Token{

      token?:string
   
}
//表单传到后台服务器
function userLogin(userName:string,password:string,protect:string,uuid:string){
      return http.request<Token>({
        url:`login`,
         method: "post",
        params:{
          userName:userName,
          password:password,
          protect: protect,
          uuid:uuid
        }
      })
}



//发送请求，验证token是否过期或合法

function  checkToken(){
  return http.request({
      url:"checkToken",
      method: "get",
      headers: {token:utils.store.get(CacheEnum.TOKEN_NAME)},
  })
}



//用户退出

function userLogout(){
    return http.request({
      url:'logout',
      method: "get",
      headers: {token:utils.store.get(CacheEnum.TOKEN_NAME)},

    })
}


//获取验证码
function getProtect(){
  return http.request({
    url:'protect',
    method: "get",

  })
}

export default {userLogout,userLogin,userInfo,checkToken,getProtect}